package com.xinfu.newproject.apiservice;

import com.xinfu.newproject.bean.certifition.AddRoomBean;
import com.xinfu.newproject.bean.certifition.QeuryRoomBean;
import com.xinfu.newproject.bean.certifition.ResidentCertificationBean;
import com.xinfu.newproject.bean.certifition.UntyingBean;
import com.xinfu.newproject.bean.community.ExistCommunityBean;
import com.xinfu.newproject.bean.community.GetCommunityBean;
import com.xinfu.newproject.bean.community.InsertCommunityBean;
import com.xinfu.newproject.bean.complaint.bean.ComplaintDetailBean;
import com.xinfu.newproject.bean.complaint.bean.ComplaintEvaluateBean;
import com.xinfu.newproject.bean.complaint.bean.ComplaintRecordBean;
import com.xinfu.newproject.bean.complaint.bean.SubmitComplaintBean;
import com.xinfu.newproject.bean.home.bean.GetAppIconBean;
import com.xinfu.newproject.bean.login.LoginBean;
import com.xinfu.newproject.bean.login.PhoneBean;
import com.xinfu.newproject.bean.login.SMSCodeBean;
import com.xinfu.newproject.bean.matter_repair.AddRepairBean;
import com.xinfu.newproject.bean.matter_repair.QueryRepairPartsBean;
import com.xinfu.newproject.bean.matter_repair.RepairDetailBean;
import com.xinfu.newproject.bean.matter_repair.RepairRecordBean;
import com.xinfu.newproject.bean.matter_repair.bean.RepairCountBean;
import com.xinfu.newproject.bean.matter_repair.bean.RepairEvaluateBean;
import com.xinfu.newproject.bean.meter.bean.AddUserMeterBean;
import com.xinfu.newproject.bean.meter.bean.CheckMeterCodeBean;
import com.xinfu.newproject.bean.meter.bean.MeterListBean;
import com.xinfu.newproject.bean.park_bean.bean.AddMonthCarBean;
import com.xinfu.newproject.bean.park_bean.bean.CheckMonthParkBean;
import com.xinfu.newproject.bean.park_bean.bean.FeeListBean;
import com.xinfu.newproject.bean.park_bean.bean.GetMonthCarListBean;
import com.xinfu.newproject.bean.park_bean.bean.GetParkingBean;
import com.xinfu.newproject.bean.park_bean.bean.MonthCarPayBean;
import com.xinfu.newproject.bean.park_bean.bean.PaymentsBean;
import com.xinfu.newproject.bean.park_bean.bean.TempPayBean;
import com.xinfu.newproject.bean.pay.PayBean;
import com.xinfu.newproject.bean.pay.bean.PayCostBean;
import com.xinfu.newproject.bean.paycost.bean.ComputeParkingBean;
import com.xinfu.newproject.bean.paycost.bean.GetBillByTypeBean;
import com.xinfu.newproject.bean.paycost.bean.QueryTypesBean;
import com.xinfu.newproject.bean.person.bean.PersonBean;
import com.xinfu.newproject.bean.up_image.UpImageBean;
import com.xinfu.newproject.contants.Constant;

import java.io.File;
import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import okhttp3.MultipartBody;
import retrofit2.http.Field;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.HeaderMap;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.Query;
import retrofit2.http.QueryMap;
import retrofit2.http.Streaming;
import retrofit2.http.Url;

public class JsNetworkService {
    /**
     * 全局变量的持有,已经改成Dagger2了
     */
    private static JsNetworkService instance = new JsNetworkService(new RetrofitClient(Constant.baseUrl));
    private static JsNetworkService instance1 = new JsNetworkService(new RetrofitClient(Constant.baseUrl1));
    private static JsNetworkService instance2 = new JsNetworkService(new RetrofitClient(Constant.baseUrl2));
    private static JsNetworkService instance3 = new JsNetworkService(new RetrofitClient(Constant.baseUrl3));

    /**
     * 构造方法私有化
     * 初始化过程会初始化mIJsNetworkService
     *
     * @param retrofitClient
     */
    public JsNetworkService(RetrofitClient retrofitClient) {
        mIJsNetworkService = retrofitClient.create(JsNetworkService.IJsNetworkService.class);
    }


    /**
     * 提供一个全局访问点
     *
     * @return
     */
    public static JsNetworkService getInstance() {
        return instance;
    }

    /**
     * 提供一个全局访问点
     *
     * @return
     */
    public static JsNetworkService getInstance1() {
        return instance1;
    }

    public static JsNetworkService getInstance2() {
        return instance2;
    }

    public static JsNetworkService getInstance3() {
        return instance3;
    }

    //网络请求服务的接口
    public IJsNetworkService mIJsNetworkService;


    public IJsNetworkService getIJsNetworkService() {
        return mIJsNetworkService;
    }

//---------------------------------------------------------------------------------------------------//

    // 所有请求服务的接口
    public interface IJsNetworkService {

        /**
         * 校验手机号
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("sys/checkUser")
        Observable<PhoneBean> getPhone(@FieldMap Map<String, String> paraMap);

        /**
         * 获取验证码
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("sys/sms")
        Observable<SMSCodeBean> getSMSCode(@FieldMap Map<String, String> paraMap);

        /**
         * 注册
         *
         * @param paraMap
         * @return
         */
        @FormUrlEncoded
        @POST("sys/regist")
        Observable<LoginBean> getRegisterData(@FieldMap Map<String, String> paraMap);

        /**
         * 登录
         *
         * @param paraMap
         * @return
         */
        @FormUrlEncoded
        @POST("sys/login")
        Observable<LoginBean> getLoginData(@FieldMap Map<String, String> paraMap);

        /**
         * 首页报修待评价和待支付数量
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("repair/repairCount")
        Observable<RepairCountBean> repairCount(@Header("X-Access-Token") String token, @Field("userId") String userId);

        /**
         * 获取小区
         *
         * @param
         * @return
         */
//        @FormUrlEncoded
        @POST("project/getProject")
        Observable<GetCommunityBean> getCommunityData(@Header("X-Access-Token") String token);

        /**
         * 更新个人信息
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("sys/updateUserInfo")
        Observable<PersonBean> updateUserInfo(@Header("X-Access-Token") String token, @FieldMap Map<String, Object> paraMap);

        /**
         * 获取首页数据
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("sys/getAppIcon")
        Observable<GetAppIconBean> getAppIcon(@Header("X-Access-Token") String token, @FieldMap Map<String, String> paraMap);

        /**
         * 新增小区
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("project/insertProjectUser")
        Observable<InsertCommunityBean> insertCommunityData(@Header("X-Access-Token") String token, @FieldMap Map<String, String> paraMap);

        /**
         * 查询房间号
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("project/getFloorRoom")
        Observable<QeuryRoomBean> queryRoomData(@Header("X-Access-Token") String token, @FieldMap Map<String, String> paraMap);

        /**
         * 添加房产
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("project/addProperty")
        Observable<AddRoomBean> addRoomData(@Header("X-Access-Token") String token, @FieldMap Map<String, Object> paraMap);

        /**
         * 解除房产
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("project/untying")
        Observable<UntyingBean> untying(@Header("X-Access-Token") String token, @Field("id") String id);

        /**
         * 查询已有房产
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("project/getProject")
        Observable<ExistCommunityBean> existCommunity(@Header("X-Access-Token") String token, @FieldMap Map<String, Object> paraMap);

        /**
         * 获取已添加房产
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("project/getProperty")
        Observable<ResidentCertificationBean> queryProperty(@Header("X-Access-Token") String token, @FieldMap Map<String, Object> paraMap);

        /**
         * 获取报修部位
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("repair/getRepairParts")
        Observable<QueryRepairPartsBean> queryRepair(@Header("X-Access-Token") String token, @FieldMap Map<String, Object> paraMap);

        /**
         * 查询报事报修
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("repair/repairRecords")
        Observable<RepairRecordBean> queryRepairRecord(@Header("X-Access-Token") String token, @FieldMap Map<String, Object> paraMap);

        /**
         * 查询报事报修详情
         *
         * @param
         * @return
         */
//        @FormUrlEncoded
        @POST("repair/repairDetail")
        Observable<RepairDetailBean> queryRepairDetail(@Header("X-Access-Token") String token, @Query("repairId") String repairId);

        /**
         * 提交报修
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("repair/repairAdd")
        Observable<AddRepairBean> submitRepair(@Header("X-Access-Token") String token, @FieldMap Map<String, Object> paraMap);
/************************************************************************************************************************************************************************************************/
        /**
         * 报修支付接口
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("charge/charge/appIntoPay")
        Observable<PayBean> getPay(@HeaderMap() Map<String, Object> headerMap, @FieldMap() Map<String, Object> map);

        /**
         * 物业费支付接口
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("charge/charge/appIntoPay")
        Observable<PayCostBean> getPayCost(@HeaderMap() Map<String, Object> headerMap, @FieldMap() Map<String, Object> map);
        /**
         * 评价接口
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("repair/repairEvaluate")
        Observable<RepairEvaluateBean> repairEvaluate(@Header("X-Access-Token") String token, @FieldMap() Map<String, Object> map);
        /**
         * 上传图片
         *
         * @param
         * @return
         */
        @Multipart
        @POST("sys/common/uploadImage")
        Observable<UpImageBean> upImage(@Part List<MultipartBody.Part> partList);
/************************************************************************************************************************************************************************************************/
        /**
         * 停车模块
         *
         */
        /**
         * 查询停车场
         *
         * @param
         * @return
         */
//        @FormUrlEncoded
        @POST("park/getParkingLot")
        Observable<GetParkingBean> getParkingLot(@Header("X-Access-Token") String token, @Query("userId") String userId);

        /**
         * 月卡车续费记录
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("car/car/app/feeList")
        Observable<FeeListBean> feeList(@Header("tenantId") String tenantId, @FieldMap() Map<String, Object> map);

        /**
         * 根据车场id和车牌号检查车辆信息
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("car/car/app/checkMonthParkCar")
        Observable<CheckMonthParkBean> checkMonthParkCar(@Header("tenantId") String tenantId, @FieldMap() Map<String, Object> map);

        /**
         * 添加月卡车
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("car/car/app/addMonthCar")
        Observable<AddMonthCarBean> addMonthCar(@Header("tenantId") String tenantId, @FieldMap() Map<String, Object> map);

        /**
         * 根据用户id查询月卡车列表
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("car/car/app/getMonthCarList")
        Observable<GetMonthCarListBean> getMonthCarList(@Header("tenantId") String tenantId, @FieldMap() Map<String, Object> map);

        /**
         * 月卡车支付
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("car/car/app/appIntoPay")
        Observable<MonthCarPayBean> appIntoPay(@Header("tenantId") String tenantId, @FieldMap() Map<String, Object> map);

        /**
         * 查询临停车
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("car/car/app/ComputeParkingFee")
        Observable<ComputeParkingBean> ComputeParkingFee(@Field("licensePlate") String licensePlate);

        /**
         * 临停车支付
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("car/car/app/appIntoTempPay")
        Observable<TempPayBean> tempPay(@Header("tenantId") String token, @FieldMap() Map<String, Object> map);
/***********************************************************************************************************************************************************************************************/
        /**
         * 支付方式查询
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("car/car/app/payments")
        Observable<PaymentsBean> payments(@Header("tenantId") String tenantId, @FieldMap() Map<String, Object> map);

        /******************************************************************************************************************************************************************************************/

        /**
         * 提交投诉
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("complaint/complaintAdd")
        Observable<SubmitComplaintBean> submitComplaint(@Header("X-Access-Token") String token, @FieldMap() Map<String, Object> map);

        /**
         * 投诉记录
         *
         * @param
         * @return
         */
//        @FormUrlEncoded
        @POST("complaint/complaintRecord")
        Observable<ComplaintRecordBean> complaintRecord(@Header("X-Access-Token") String token, @Query("userId") String userId);

        /**
         * 投诉详情
         *
         * @param
         * @return
         */
//        @FormUrlEncoded
        @POST("complaint/complaintDetail")
        Observable<ComplaintDetailBean> complaintDetail(@Header("X-Access-Token") String token, @Query("complaintId") String complaintId);

        /**
         * 投诉评价
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("complaint/complaintEvaluate")
        Observable<ComplaintEvaluateBean> complaintEvaluate(@Header("X-Access-Token") String token, @FieldMap() Map<String, Object> map);

/******************************************************************************************************************************************************************************************/

        /**
         * 缴费
         */
        /**
         * 查询对应的缴费类型
         *
         * @param
         * @return
         */
//        @FormUrlEncoded
        @POST("charge/charge/app/queryTypes")
        Observable<QueryTypesBean> queryTypes(@Header("tenantId") String tenantId);

        /**
         * 查询对应的缴费类型下的对应账单
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("charge/charge/app/getBillsByType")
        Observable<GetBillByTypeBean> getBillsByType(@Header("tenantId") String tenantId, @FieldMap() Map<String, Object> map);

        /**
         * 查询缴费记录
         *
         * @param
         * @return
         */
//        @FormUrlEncoded
        @POST("charge/charge/app/getUserPayRecords")
        Observable<String> getUserPayRecords(@Header("tenantId") String tenantId, @Query("userId") String userId);

        /**
         * 下载文件
         *
         * @param fileUrl
         * @return
         */
        @Streaming //大文件时要加不然会OOM
        @POST
        Observable<File> downloadFile(@Url String fileUrl);
/******************************************************************************************************************************************************************************************/
        /**
         * 手动添加水电表
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("meter/meter/foreign/addUserMeter")
        Observable<AddUserMeterBean> addUserMeter(@Header("tenantId") String tenantId, @FieldMap() Map<String, Object> map);

        /**
         * 校验meterCode是否存在
         *
         * @param
         * @return
         */
//        @FormUrlEncoded
        @GET("meter/meter/foreign/checkMeterCode")
        Observable<CheckMeterCodeBean> checkMeterCode(@Header("tenantId") String tenantId, @QueryMap() Map<String, Object> map);

        /**
         * 查询所有水电表
         *
         * @param
         * @return
         */
//        @FormUrlEncoded
        @GET("meter/meter/foreign/meterList")
        Observable<MeterListBean> meterList(@QueryMap() Map<String, Object> map);

        /**
         * 水电表支付
         *
         * @param
         * @return
         */
        @FormUrlEncoded
        @POST("meter/meter/foreign/pay")
        Observable<MeterListBean> meterPay(@Header("tenantId") String tenantId, @FieldMap() Map<String, Object> map);


    }

}
